package controller;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.nimbus.NimbusLookAndFeel;

import model.Receiver;
import util.SocketUtil;
import view.ChessPanel;
import view.InfoPanel;
import view.LoginPanel;

public class MainInterface extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public MainInterface() {
		setSize(1300, 800);
		setLayout(new BorderLayout());
		setVisible(true);
		getToolkit();
		Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((ds.width - getWidth()) / 2, (ds.height - getHeight()) / 2);
		setResizable(false);
		setDefaultCloseOperation(EXIT_ON_CLOSE);

		LoginPanel loginPanel = new LoginPanel();
		setGlassPane(loginPanel);
		loginPanel.setVisible(true);

		ChessPanel chessPanel = new ChessPanel();
		add(chessPanel);

		InfoPanel infoPanel = new InfoPanel();
		add(infoPanel, BorderLayout.EAST);

		Receiver receiver = new Receiver();
    	receiver.addObserver(loginPanel);
		receiver.addObserver(chessPanel);
		receiver.addObserver(infoPanel);

		SocketUtil.getUser().addObserver(chessPanel);
		SocketUtil.getUser().addObserver(infoPanel);

		SocketUtil.setReceiver(receiver);
		SocketUtil.startServer();

	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {

			public void run() {
				try {
					UIManager.setLookAndFeel(new NimbusLookAndFeel());       //风格
				} catch (UnsupportedLookAndFeelException e) {
					e.printStackTrace();
				}
				new MainInterface();
			}
		});
	}

}
